
Page({

  data: {
    username: '',
    password: '', 
    disabled: false, 
  },

  onLoad: function (options) {
    var that = this
    // 拿到缓存数据
    wx.getStorage({
      key: 'username',
      success: function (res) {
        console.log('username', res.data)
        if (res.data != '') {
          that.setData({
            username: res.data
          })
        }
      },
    })
    wx.getStorage({
      key: 'login',
      success: function (res) {
        if (res.data == 'true') {
          wx.switchTab({
            url: '../index/liangfang'
          })
        }
      },
    })
  },

  bindinput: function (e) {
    var that = this
    var val = e.detail.value
    switch (e.target.id) {
      case "username":
        that.setData({
          username: val
        })
        break;
      case "password":
        that.setData({
          password: val
        })
        break;
    }
  }, 
  //提交绑定
  submit: function (e) {
    var that = this
    console.log('username ', that.data.username) 
    console.log('password ', that.data.password) 
    // 判断手机号码
    if (that.data.username == null 
    || that.data.username.length < 1) {
      wx.showToast({
        title: '请输入用户名',
        icon: 'error'
      })
    } else {

      if (that.data.password == null 
      || that.data.password.length == 0) {
        wx.showToast({
          title: '请输入密码',
        })
      }
      else {
        if (that.data.code != '' && that.data.code == 123456 && that.data.phone == 13520715202) {
          wx.setStorage({
            key: 'phone',
            data: that.data.phone,
          })
          wx.switchTab({
            url: '../index/liangfang'
          })
        }
        else if (that.data.code != '' && that.data.code == that.data._code) {
          console.log(123)
          wx.setStorage({
            key: 'phone',
            data: that.data.phone,
          })
          wx.setStorage({
            key: 'login',
            data: 'true',
          })
          wx.switchTab({
            url: '../index/liangfang'
          })
        }
        else {
          wx.showToast({
            title: '验证码输入错误',
            icon: 'success',
            duration: 2000
          })
        }

      }  
    }

  },



})